<template>
  <div class="mainerRight">
    <div class="header">
      <div class="info">
        <!-- 图片 -->
        <div class="cover">
          <img :src="playList.coverImgUrl" />
          <div class="mask"></div>
        </div>
        <!-- 文字信息 -->
        <div class="cnt">
          <div class="hd">
            <h4>{{ playList.name }}</h4>
          </div>
          <div class="user">
            <i class="icn" style="overflow: hidden"></i>
            <span class="sep">网易云音乐官方账号</span>
            <span class="fc">{{ num }}</span>
          </div>
          <!-- 底部按钮 -->
          <div class="btns">
            <a class="play" title="播放">
              <i class="ply"></i>
              <span>播放</span>
            </a>
            <a class="add"></a>
            <a class="dis">
              <span>({{ playList.subscribedCount }})</span>
            </a>
            <a class="share">
              <span>(13501)</span>
            </a>
            <a class="download">
              <span>下载</span>
            </a>
            <a class="comment">
              <span>(217500)</span>
            </a>
          </div>
        </div>
      </div>
    </div>

    <div class="songList">
      <div class="tlt">
        <h3>歌曲列表</h3>
        <span class="sub">{{ length }}首歌</span>
        <div class="more">
          播放：<span class="fc">{{ playCount }} </span>次
        </div>
      </div>
      <div class="song">
        <div class="header">
          <li class="w1"></li>
          <li class="w2">标题</li>
          <li class="w3">时长</li>
          <li class="w4">歌手</li>
        </div>
        <div class="mainer">
          <ul
            v-for="(song, index) in songList"
            :key="index"
            :class="{ good: index < 3 }"
          >
            <li class="m1">
              <span>{{ index + 1 }}</span>
              <i></i>
            </li>
            <li class="m2">
              <img :src="song.al.picUrl" v-show="index < 3" />
              <i class="play" @click="setMusic(song.id, index)"></i>
              <router-link
                :to="{ path: '/song', query: { id: `${song.id}` } }"
                :title="song.name"
                >{{ song.name }}</router-link
              >
              <i class="mv"></i>
            </li>
            <li class="m3">
              <span class="time">{{ min(song) }}:{{ sec(song) }}</span>
              <div class="show">
                <a
                  text="添加到播放列表"
                  class="a1"
                  @click="addMusicList(song.id)"
                ></a>
                <a text="收藏" class="a2"></a>
                <a text="分享" class="a3"></a>
                <a text="下载" class="a4"></a>
              </div>
            </li>
            <li class="m4">
              <router-link
                :to="{ path: '/artist/song', query: { id: song.ar[0].id } }"
                >{{ song.ar[0].name }}</router-link
              >
            </li>
          </ul>
        </div>
      </div>
    </div>
    <Comment />
  </div>
</template>

<script>
import Comment from "./Comment.vue";
import { GeiListApi, GetAllMusicListApi } from "@/request/api";
export default {
  data() {
    return {
      playList: {},
      num: "刚刚更新",
      songList: [],
      length: 0,
      playCount: 0,
    };
  },
  computed: {
    id() {
      if (this.$route.query.id == undefined) return "19723756";
      return this.$route.query.id;
    },
  },
  methods: {
    min(song) {
      if (parseInt(song.dt / 60000) < 10)
        return "0" + parseInt(song.dt / 60000);
      else return parseInt(song.dt / 60000);
    },
    sec(song) {
      let x = parseInt(song.dt / 60000);
      let y = parseInt(song.dt / 1000 - x * 60);
      if (y < 10) return "0" + y;
      else return y;
    },
    // 播放音乐
    setMusic(id, index) {
      this.$store.commit("pushMusicLi", { id, index });
      this.$store.commit(
        "changeMusicId",
        this.$store.state.musicli[this.$store.state.musicli.length - 1]
      );
    },
    getdatas() {
      GeiListApi(this.id).then((res) => {
        this.songList = res.data.songs;
      this.$store.commit("changeSongList", this.songList);
        this.length = this.songList.length;
      });
    },
  },
  mounted() {
    GetAllMusicListApi().then((res) => {
      let arr = res.data.list;
      arr.forEach((item) => {
        if (item.id == this.id) {
          this.playList = item;
          this.playCount = item.playCount;
          return;
        }
      });
    });
    this.getdatas();
  },
  components: {
    Comment,
  },watch:{
    id(){
    this.getdatas();
    }
  },
};
</script>

<style lang='less' scoped>
.mainerRight {
  width: 740px;
  background-color: #fff;
  float: right;
  .header {
    width: 100%;
    height: 238px;

    .info {
      width: 100%;
      height: 100%;
      display: flex;

      .cover {
        width: 158px;
        height: 158px;
        padding: 3px;
        border: 1px solid #ccc;
        position: relative;

        img {
          width: 150px;
          height: 150px;
        }

        .mask {
          width: 150px;
          height: 150px;
          position: absolute;
          z-index: 2;
          top: 3px;
          left: 3px;
          background: url("@/assets/image/toplist/coverall.png") no-repeat -230px -380px;
        }
      }

      .cnt {
        text-align: left;
        width: 473px;
        height: 114px;
        margin-top: 20.5px;
        padding-left: 33px;
        .hd {
          width: 473px;
          height: 24px;
          h4 {
            font-weight: normal;
            font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif !important;
            font-size: 20px;
            color: #333;
          }
        }
        .user {
          margin-top: 5px;
          width: 100%;
          height: 35px;
          line-height: 35px;
          margin-bottom: 20px;

          i {
            display: inline-block;
            width: 13px;
            height: 13px;
            position: relative;
            top: 2px;
            margin-left: 3px;
            background: url("@/assets/image/toplist/icon.png") no-repeat -18px -682px;
          }
          .sep {
            margin-right: 10px;
            margin-left: 5px;
          }
        }
        .btns {
          height: 31px;
          display: flex;

          .play {
            width: 66px;
            padding-left: 5px;
            background: url("@/assets/image/toplist/button2.png") no-repeat 0 -1652px;
            text-align: center;
            line-height: 31px;
            height: 31px;
            border-top-left-radius: 5px;
            border-bottom-left-radius: 5px;

            i {
              width: 20px;
              height: 18px;
              margin: 6px 2px 2px 0;
              float: left;
              background: url("@/assets/image/toplist/button2.png") no-repeat 0 -1622px;
            }

            span {
              color: #fff;
            }
            &:hover {
              cursor: pointer;
            }
          }

          .add {
            width: 31px;
            height: 31px;
            margin-right: 5px;
            background: url("@/assets/image/toplist/button2.png") no-repeat 0 -1588px;

            &:hover {
              cursor: pointer;
              background-position: -40px -1588px;
            }
            &:active {
              background-position: -80px -1588px;
            }
          }

          .dis {
            width: 92.6px;
            // padding-right: 5px;
            margin-right: 6px;
            height: 100%;
            background: url("@/assets/image/toplist/button2.png") no-repeat;
            background-position: 0px -1063px;
            span {
              display: inline-block;
              height: 100%;
              width: 70%;
              background: url("@/assets/image/toplist/button2.png") no-repeat
                right -1106px;
              line-height: 30px;
              padding-left: 30px;
            }
            &:hover {
              color: #666;
              cursor: pointer;
            }
          }

          .share {
            width: 79.8px;
            height: 31px;
            margin-right: 6px;
            float: left;
            line-height: 30px;
            min-width: 23px;
            cursor: pointer;
            background: url("@/assets/image/toplist/button2.png") no-repeat;
            background-position: 0 -1225px;

            span {
              width: 66%;
              height: 100%;
              display: inline-block;
              line-height: 30px;
              padding-left: 28px;
              background: url("@/assets/image/toplist/button2.png") no-repeat;
              background-position: right -1020px;
            }

            &:hover {
              color: #666;
              cursor: pointer;
            }
          }

          .download {
            margin-right: 5px;
            width: 60px;
            height: 31px;
            line-height: 30px;
            min-width: 23px;
            cursor: pointer;
            background: url("@/assets/image/toplist/button2.png") no-repeat;
            background-position: 0 -2761px;

            span {
              width: 55%;
              height: 100%;
              display: inline-block;
              line-height: 30px;
              padding-left: 28px;
              background: url("@/assets/image/toplist/button2.png") no-repeat;
              background-position: right -1020px;
            }
            &:hover {
              color: #666;
              cursor: pointer;
            }
          }

          .comment {
            margin-right: 5px;
            width: 90px;
            height: 31px;
            line-height: 30px;
            min-width: 23px;
            cursor: pointer;
            background: url("@/assets/image/toplist/button2.png") no-repeat;
            background-position: 0 -1465px;

            span {
              width: 72%;
              height: 100%;
              display: inline-block;
              line-height: 30px;
              padding-left: 28px;
              background: url("@/assets/image/toplist/button2.png") no-repeat;
              background-position: right -1020px;
            }
            &:hover {
              color: #666;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
}

.songList {
  width: 670px;
  min-height: 400px;
  margin: 0 auto;
  .tlt {
    width: 100%;
    height: 35px;
    border-bottom: 2px solid #c20c0c;

    h3 {
      font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
      font-size: 20px;
      line-height: 28px;
      font-weight: normal;
      color: #333;
      float: left;
    }

    .sub {
      margin: 9px 0 0 20px;
      float: left;
      color: #666;
      font-size: 12px;
      font-family: Arial, Helvetica, sans-serif;
      -webkit-text-size-adjust: none;
    }

    .more {
      margin-top: 5px;
      height: 16px;
      float: right;

      .fc {
        color: #c20c0c;
        font-weight: bold;
      }
    }
  }
  .song {
    width: 100%;
    border: 1px solid #d9d9d9;
    .header {
      width: 100%;
      height: 39px;
      display: flex;
      li {
        border-right: 1px solid #d9d9d9;
        background-image: linear-gradient(
          rgb(255, 255, 255),
          rgb(240, 240, 240)
        );
        padding: 8px 10px;
        box-shadow: 0 1px 1px 1px rgba(0, 0, 0, 0.1);
      }
      .w1 {
        width: 77px;
      }
      .w2 {
        width: 326px;
      }
      .w3 {
        width: 91px;
      }
      .w4 {
        width: 174px;
      }
    }

    .mainer {
      width: 100%;
      display: block;
      ul:nth-of-type(even) {
        background: #e5e5e5;
      }
      ul:nth-of-type(odd) {
        background: #f6f6f6;
      }
      .good {
        height: 70px;
        span,
        a,
        i {
          display: block;
          margin-top: 20px !important;
        }
      }
      ul {
        height: 30px;
        width: 100%;
        display: flex;

        &:hover .time {
          display: none !important;
        }
        &:hover .show {
          display: block !important;
        }

        li {
          padding: 6px 10px;
        }

        .m1 {
          width: 77px;
          // height: 100%;
          padding: 6px 10px;
          line-height: 18px;
          span {
            float: left;
            width: 25px;
            height: 18px;
            color: #999;
            text-align: center;
          }
          i {
            margin: 0 8px;
            float: left;
            width: 16px;
            height: 17px;
            background: url(@/assets/image/toplist/icon.png) no-repeat -67px -283px;
          }
        }

        .m2 {
          width: 326px;

          img {
            float: left;
            margin-right: 10px;
            width: 50px;
          }
          .play {
            float: left;
            display: block;
            width: 17px;
            height: 17px;
            margin-right: 8px;
            background: url("@/assets/image/toplist/table.png") no-repeat -0px -103px;

            &:hover {
              background-position: -0px -128px;
              cursor: pointer;
            }
            // background: url("@/assets/image/toplist/table.png") no-repeat -20px -128px;
          }
          a {
            width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            float: left;
            &:hover {
              color: #666;
              cursor: pointer;
              text-decoration: underline;
            }
          }
        }

        .m3 {
          width: 91px;
          .time {
            display: block;
          }
          .show {
            width: 79px;
            height: 18px;
            display: none;
            a {
              margin: 2px 0 0 4px;
              width: 18px;
              height: 16px;
              display: block;
              float: left;
              background: url("@/assets/image/toplist/table.png") no-repeat;
              &:hover {
                cursor: pointer;
              }
            }
            .a1 {
              width: 13px;
              height: 13px;
              margin-top: 2px;
              margin-left: 0;
              background: url("@/assets/image/toplist/icon.png") no-repeat;
              background-position: 0 -700px;

              &:hover {
                background-position: -22px -700px;
              }
            }

            .a2 {
              background-position: 0 -174px;
              &:hover {
                background-position: -20px -174px;
              }
            }
            .a3 {
              background-position: 0 -195px;
              &:hover {
                background-position: -20px -195px;
              }
            }
            .a4 {
              background-position: -81px -174px;
              &:hover {
                background-position: -104px -174px;
              }
            }
          }
        }

        .m4 {
          width: 173px;
          color: #333;
          & a:hover {
            color: #666;
            cursor: pointer;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
</style>